using System;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using mfRCF.Core;
using mfRCF.Core.Extensions;

using mfXmlSerializer;

using mfLogger;

using OST.Commands.Extensions;
using OST.Persistence;
using OST.Shared;


namespace OST.Commands
{

    /// <summary>
    /// return the Uptime of the system
    /// </summary>
    public class UptimeGETCommand : mfRcfCommand
    {
        #region CTOR

        public UptimeGETCommand(string httpPath)
            : base(httpPath, new mfGETMethod())
        {
        }

        #endregion



        #region mfRcfCommand
        public override void ExecuteCommand(mfIHttpContext httpContext)
        {
            try
            {
                if (!ConfigurationProvider.Instance.HasConfig)
                    throw new OSTException("no config available");

                var config = ConfigurationProvider.Instance.ConfigInstance;
                var uptime = DateTime.Now - config.TimeService.Value;

                this.WriteHttpResponseOK(httpContext, uptime.ToString());
            }
            catch (Exception ex)
            {
                this.WriteHttpResponseError(httpContext, ex);
            }
        }

        #endregion
    }
}
